---
description: "Reference for Nitric's Node.js library - Send messages to a queue."
---

# Node.js - queue.enqueue()

<Note>
  This is reference documentation for the Nitric Node.js SDK. To learn about
  Queues in Nitric start with the [Async Messaging docs](/messaging#queues).
</Note>

Send messages to a queue.

```javascript
import { queue } from '@nitric/sdk'

const batchQueue = queue('batch').allow('enqueue')

await batchQueue.enqueue({ example: 'value' })
```

## Parameters

<Properties>
  <Property name="messages" required type="Object or Object[]">
    A message or an array of messages to send to the queue.
  </Property>
</Properties>

## Examples

### Send a message to a queue

```javascript
import { queue } from '@nitric/sdk'

const batchQueue = queue('batch').allow('enqueue')

const item = { message: 'payloads can be any serializable object' }

await batchQueue.enqueue(item)
```

### Send multiple messages to a queue

```javascript
import { queue } from '@nitric/sdk'

const batchQueue = queue('batch').allow('enqueue')

const items = [
  {
    type: 'Email',
    to: 'hello@example.com',
    subject: 'Notification',
    message: 'A notification from Nitric',
  },
  {
    type: 'SMS',
    to: '+17200000000',
    message: 'A text message from Nitric',
  },
]

await batchQueue.enqueue(items)
```

### Dealing with failures

In rare cases when enqueueing messages some might fail to be sent. The response from `enqueue()` will include an array of any messages that failed to send. You can process this array to retry or log the error.

```javascript
const failed = await batchQueue.enqueue(messages)

for (const message in failed) {
  console.log(message)
}
```
